//
// Created by Administrator on 2018/11/21.
//

#ifndef VIDEODEMO_SIMPLEPLAYER_H
#define VIDEODEMO_SIMPLEPLAYER_H


#include <Log.h>
#include <queue>
#include <thread>
#include<mutex>
#include <unistd.h>


using namespace std;



class SimplePlay {
private:
    AVFormatContext *formatContext;
    AVCodecContext *videoContext;
    AVCodecContext *audioContext;
    AVCodec *videoCodec;
    AVCodec *audioCodec;
    int audioStream = -1;
    int videoStream = -1;
    queue<AVFrame*> videoFrameQueue;
    queue<AVFrame*> audioFrameQueue;
    queue<AVPacket*> videoPktQueue;
    queue<AVPacket*> audioPktQueue;
    int MAX_PKT_SIZE=1000;
    int MAX_FRAME_SIZE=10;
    JavaVM *javaVM;
    jobject instance;
    ANativeWindow *pANativeWindow;
    mutex videoPktMutex;
    mutex audioPktMutex;
    mutex videoFrameMutex;
    mutex audioFrameMutex;
    double audio_clock;

    AVPacket* getAudioPacket();
    AVPacket* getVideoPacket();
    AVFrame* getAudioFrame();
    AVFrame* getVideoFrame();

public:
    void open(JavaVM *javaVM, jobject instance, const char *filePath, ANativeWindow *pANativeWindow);

    void read();

    void decodeVideo();

    void decodeAudio();

    void playVideo();

    void playAudio();
};

#endif //VIDEODEMO_SIMPLEPLAYER_H
